<script>

import * as echarts from 'echarts';
export default {
  name: 'VisualizationTwo',
  data() {
    return{

    }
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      this.$axios.get('/api/vis/data11', {

      }).then(res =>{
        if(res.data.code === 20041) {
          let data1 = [];
          let data2 = [];
          let data3 = [];
          for (let i = 0; i < res.data.data.length; i++) {
            data1.push(
                res.data.data[i].param
            );
            data2.push(
                res.data.data[i].param1
            )
          }
          this.$axios.get('/api/vis/data12', {

          }).then(res =>{
            if(res.data.code === 20041) {
              for (let i = 0; i < res.data.data.length; i++) {
                data3.push(
                    res.data.data[i].param1
                )
              }
              this.init(data1, data2, data3);
            }
          }).catch(error =>{
            this.open4(error);
          })

        }
      }).catch(error =>{
        this.open4(error);
      })
    },
    open4(msg) {
      this.$notify.error({
        title: msg,
        message: '这是一条错误的提示消息'
      });
    },
    init(data1, data2, data3) {
      var chartDom = document.getElementById('main2');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        title: {
          text: "堆叠图",
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        legend: {
          data: data1
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'value'
        },
        yAxis: {
          type: 'category',
          data: ['景区评分', '景区热度']
        },
        series: [
            {
            name: '' + data1[0],
            type: 'bar',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'insideRight'
              }
            },
            z: 10,
            data: [data2[0], data3[0]]
          },
          {
            name: '' + data1[1],
            type: 'bar',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'insideRight'
              }
            },
            z: 10,
            data: [data2[1], data3[1]]
          },
          {
            name: '' + data1[2],
            type: 'bar',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'insideRight'
              }
            },
            z: 10,
            data: [data2[2], data3[2]]
          },
          {
            name: '' + data1[3],
            type: 'bar',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'insideRight'
              }
            },
            z: 10,
            data: [data2[3], data3[3]]
          },
          {
            name: '' + data1[4],
            type: 'bar',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'insideRight'
              }
            },
            z: 10,
            data: [data2[4], data3[4]]
          },
          {
            name: '' + data1[5],
            type: 'bar',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'insideRight'
              }
            },
            z: 10,
            data: [data2[5], data3[5]]
          },
          {
            name: '' + data1[6],
            type: 'bar',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'insideRight'
              }
            },
            z: 10,
            data: [data2[6], data3[6]]
          },
          {
            name: '' + data1[7],
            type: 'bar',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'insideRight'
              }
            },
            z: 10,
            data: [data2[7], data3[7]]
          },
          {
            name: '' + data1[8],
            type: 'bar',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'insideRight'
              }
            },
            z: 10,
            data: [data2[8], data3[8]]
          },
        ]
      };
      option && myChart.setOption(option);

    }
  }

}
</script>

<template>
  <div id="main2"></div>
</template>

<style scoped>
#main2 {
  width: 100%;
  height: 100%;
}
</style>